package com.bryantkobe.myspringcode.controller;

import com.bryantkobe.myspringcode.entity.Customer;
import com.bryantkobe.myspringcode.service.IPostgreSQLService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description: PostgreSQL数据库相关controller
 * @author: alienwarezzl
 * @date: 2025/9/17
 */
@RestController
@RequestMapping("/postgresql")
@Tag(name = "PostgreSQL模块",description = "用于测试PostgreSQL模块")
public class PostgreSQLController {

    @Resource
    private IPostgreSQLService iPostgreSQLService;

    @Operation(summary = "/insertCustomer",description = "插入postgresql数据库customer数据")
    @GetMapping("/insertCustomer")
    public void insertCustomer() {
        Customer customer = new Customer();
        customer.setCustomerName("A");
        customer.setCustomerId(1);
        customer.setOriginalCustomerId(1);
        customer.setLocation("ab");
        customer.setSegment("a");
        customer.setIsCurrent(true);

        Boolean success = iPostgreSQLService.insertCustomer(customer);

        System.out.println("A:"+success);
    }

    @Operation(summary = "deleteCustomerByCustomerId",description = "根据customerId删除Customer")
    @PostMapping("/deleteCustomerByCustomerId")
    public Boolean deleteCustomerByCustomerId(Integer customerId) {
        Boolean success = iPostgreSQLService.deleteCustomerByCustomerId(customerId);
        return success;
    }
}
